package com.nubia.controller;
import com.nubia.dao.ShopsDao;
import com.nubia.entity.Shops;
import com.nubia.entity.User;
import com.nubia.service.ShopsService;
import com.nubia.utils.JwtUtils;
import com.nubia.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.ognl.ASTProject;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@RestController
@RequestMapping("shop")
@Slf4j
@CrossOrigin

public class ShopsController {
    @Autowired
    ShopsService shopsService;
    /**
     *获取所有的商品  返回一个商品列表
     * @return
     */

    @RequestMapping("/getShopsList")
    public Map<String,Object> getAllShops(){
            List<Shops> shopsList = shopsService.findAllShops();
            if (shopsList != null)
            {
                return Result.resultData("获取成功",true,shopsList);
            }else {
                return Result.resultData("获取失败",false,null);
            }
    }
    /**
     * 添加商品
     */
    @RequestMapping("/addShop")
    public Map<String,Object> intoInsShop(@RequestBody Shops shops){

        //设置shop_id随机
        shops.setShop_id(UUID.randomUUID().toString());
        if (shops.getShop_name() != null ){
            int i = shopsService.addShop(shops);
            if (i == 0){
                return Result.resultDataString("加入商品失败",false,"失败");
            }else {
                return Result.resultDataString("加入商品成功",true,"success");
            }

        }else {
            return Result.resultDataString("已经存在该商品",false,"请换其他商品");
        }


    }
}
